package edu.office.applicationRepository;

import edu.office.entities.Edulevel;
import edu.office.entities.School;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@ApplicationScoped
public class EdulevelRepository extends ApplicationCommonRepository<Edulevel> {
    @Inject
    SchoolRepository schoolRepository;

    HashMap<Integer, Set<School>> schoolSetAts=new HashMap<>();
    HashMap<Integer,Boolean> dirtySchoolAts=new HashMap<>();
    List<Edulevel> allEdulevel;
    public EdulevelRepository(){
        allEdulevel=listAll();
        for(Edulevel edu:allEdulevel){//默认数据都不脏
            dirtySchoolAts.put(edu.getID(),Boolean.FALSE);
        }
    }

    public Set<School> getSchoolAt(int eduLevel){
        if(null==schoolSetAts.get(eduLevel)||dirtySchoolAts.get(eduLevel)){
            schoolSetAts.put(eduLevel, new HashSet<>(schoolRepository.list("edulevel", eduLevel)));
        }
        return schoolSetAts.get(eduLevel);
    }

}
